package cn.cdeden.knowledge.domain.dto;


import cn.cdeden.common.mybatis.validator.Query;
import cn.cdeden.knowledge.utils.DateUtil;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author GW
* @date 2024-01-19
*/
@Getter
@Setter
public class SysDocLogQueryParam {

    String nickName;

    String deptName;

    @Query
    String documentId;

    @Query(type = Query.Type.BETWEEN)
    List<Date> createTime;

    @Query
    @Pattern(regexp = "enterprise|team", message = "查询日志参数错误")
    String documentType;

    public void setType(String type) {
        Date startDay = null;
        Date endDay = null;
        switch (type) {
            case "today":
                startDay = DateUtil.getStartDay();
                endDay = DateUtil.getEndDay();
                break;
            case "week":
                startDay = DateUtil.getWeeklyStart();
                endDay = DateUtil.getWeeklyEnd();
                break;
            case "month":
                startDay = DateUtil.getMonthlyStart();
                endDay = DateUtil.getMonthlyEnd();
                break;
            case "quarter":
                startDay = DateUtil.getQuarterlyStart();
                endDay = DateUtil.getQuarterlyEnd();
                break;
            case "year":
                startDay = DateUtil.getYearStart();
                endDay = DateUtil.getYearEnd();
                break;
            case "all":
                this.createTime = null;
                return;
        }
        this.createTime = new ArrayList<Date>();
        this.createTime.add(startDay);
        this.createTime.add(endDay);
    }
}
